/**
 * DataSourceInfoVO
 */
export default class DataSourceInfoVO {
    /**
     * id
     */
    id: string;

    /**
     * 数据库类型(1.mysql)
     */
    databaseType: number;

    /**
     * 数据库类型(1.mysql)
     */
    databaseTypeName: string;
    /**
     * 连接地址
     */
    host: string;
    /**
     * 连接端口
     */
    port: string;
    /**
     * 库名
     */
    schemaName: string;
    /**
     * 用户名
     */
    username: string;

    public coverFormObject(obj: any) {
        this.id = obj.id;
        this.host = obj.host;
        this.databaseType = obj.databaseType;
        this.port = obj.port;
        this.schemaName = obj.schemaName;
        this.username = obj.username;
        this.databaseTypeName = this.typeName();
    }

    public static createFormObject(obj: any): DataSourceInfoVO {
        let res = new DataSourceInfoVO();
        Object.assign(res, obj);
        res.databaseTypeName = res.typeName();
        return res;
    }

    public static typeToName(type: number): string {
        switch (type) {
            case 1:
                return "Mysql"
        }
        return "";
    }

    public typeName(): string {
        return DataSourceInfoVO.typeToName(this.databaseType);
    }
}